package com.briup.smartcity_group6.web.controller;

import com.briup.smartcity_group6.bean.basic.Comment;
import com.briup.smartcity_group6.service.ICommentService;
import com.briup.smartcity_group6.utils.Result;
import com.briup.smartcity_group6.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/auth/comment")
@Api(tags = "评论模块")
@RestController
public class CommentController {
    @Autowired
    private ICommentService service;


    @ApiOperation("条件寻找评论")
    @GetMapping("/page")
    public Result findByPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize, @RequestParam(defaultValue = "6") String keywords){
        PageInfo<Comment> commentPageInfo = service.pageQuery(pageNum,pageSize,keywords);
        return ResultUtil.success(commentPageInfo);
    }

    @ApiOperation("根据id删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id",required = true)
    })
    @DeleteMapping("")
    public Result deleteById(Integer id){
        service.deleteById(id);
        return ResultUtil.success("删除成功");
    }

    @ApiOperation("批量删除评论")
    @DeleteMapping("/batch")
    public Result batchDelect(int ids[]){
        service.batchDelete(ids);
        return ResultUtil.success("删除成功");
    }

    @ApiOperation("审核评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id",required = true),
            @ApiImplicitParam(name = "status",value = "状态",required = true)

    })
    @PutMapping("/check")
    public Result checkCom(int id, int status){
        service.checkComment(id,status);
        return ResultUtil.success("审核成功");
    }
}
